@echo off
chcp 65001 >nul

set CONTRACT_NAME=MyTestToken
set CONTRACT_FILE=.\contract\%CONTRACT_NAME%.sol
set OUTPUT_DIR=.\build\%CONTRACT_NAME%
set SOLC_PATH=.\solc-windows.exe
set SOLC_ARGS=--bin --abi --optimize --optimize-runs 200 --overwrite

if not exist "%SOLC_PATH%" (
    echo 错误：编译器未找到
    echo 请检查路径：%SOLC_PATH%
    exit /b 1
)

if not exist "%CONTRACT_FILE%" (
    echo 错误：合约文件未找到
    echo 请确检查路径：%CONTRACT_FILE%
    exit /b 1
)

if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%"

echo 正在编译合约：%CONTRACT_FILE%
"%SOLC_PATH%" %SOLC_ARGS% --output-dir "%OUTPUT_DIR%" "%CONTRACT_FILE%"

if %errorlevel% equ 0 (
    echo 编译成功
    echo 输出目录：%OUTPUT_DIR%
    echo 字节码文件：%OUTPUT_DIR%\%CONTRACT_NAME%.bin
    echo ABI文件：%OUTPUT_DIR%\%CONTRACT_NAME%.abi
) else (
    echo 编译失败
    exit /b 1
)

pause